/*
 * @Author: zhanghongqiao 
 * @Date: 2023-02-13 10:26:42 
 * @Email: 991034150@qq.com 
 * @Description: 公用store
 * @Last Modified by: zhanghongqiao
 * @Last Modified time: 2024-03-27 13:47:12
 */
  
import { defineStore } from "pinia";
import { fetch }  from '@/utils/request' 

export const commonStroe = defineStore('commonStroe',  {
  state: () => {
    return {
      logged: !!sessionStorage.getItem('oauthToken'),
      oauthToken: '',
      selectedMenuId: '',
      memuList: []
    }
  },
  actions: {
    requestMenuList() {
      fetch('fetchMemuList', data => { 
        this.memuList = data 
      })
    },
    /**
     * 设置登录状态
     */
    setLoginState(logged: boolean) { 
      this.logged = logged
    },
    
    /**
     * 设置token
     */
    setToken(token: string) {
      this.oauthToken = token 
      sessionStorage.setItem('oauthToken', token) 
    },

    /**
     * 设置左侧选中菜单id
     * @param id string
     */
    setSelectedMenuId(id: string) {
      this.selectedMenuId = id
    }
  }
}) 